package com.gopay.common.util.xml.xmlutils.tools;

import java.util.Map;

import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;

import com.gopay.common.util.Constants;
import com.gopay.common.util.xml.xmlutils.message.Message;

public class XmlUtilTools {
	
	/**
	 * 
	 * @param message
	 * @param xml
	 * @return
	 * @throws CheckMessageException
	 */
	public static Object builderObj(Message message, String xml) throws Exception {
		return X2JUtilTools.builderObj(message, xml);
	}
	
	
	/**
	 * 
	 * @param message
	 * @return
	 */
	public static String builderXml(Message message, Object data){
		return builderXml(message, data, "UTF-8");
	}
	
	/**
	 * 
	 * @param message
	 * @return
	 */
	public static String builderXml(Message message, Object data,
			String encoding){
		return J2XUtilTools.builderXml(message, data, encoding);
	}

	/**
	 * 将map转为xml
	 */
	public static String builderXml4Map(Map<String, ? extends Object> map, String rootElemName, String encode) {
		return J2XUtilTools.builderXml4Map(map, rootElemName, encode);
	}

	/**
	 * 获取文档编码格式
	 * @return 
	 */
	public static String geEncoding(String xml) {
		try {
			return DocumentHelper.parseText(xml).getXMLEncoding();
		} catch (DocumentException e) {
			e.printStackTrace();
		}
		return Constants.SYS_ENCODE_UTF8;
	}
}
